Every now and then, you'll run into a DLL function that returns a string whose return type is LPSTR or LPTSTR. You won't find too many of these in the core Win32 API, but some custom DLLs and extension libraries take this approach. Consider one example from the Win32 APIthe GetEnvironmentStrings function. Computer programs, like all living things, live in the context of an environment. The GetEnvironmentStrings function lets you examine the environment variables for an application. This function is described in the C documentation as follows:
Each process has an environment block associated with it. The environment block consists of a null-terminated block of null-terminated strings (meaning there are two null bytes at the end of the block), where each string is in the following form:
name=value
LPVOID GetEnvironmentStrings(VOID)
When GetEnvironmentStrings is called, it allocates memory for a block of environment strings. When the block is no longer needed, it should be freed by calling FreeEnvironmentStrings.
Even though the declaration is LPVOID, from the explanation you can see that it is actually returning a pointer to a string. If you look at the declaration in the Win32api.txt file that comes with Visual Basic, you'll find the function declared as follows:
Declare Function GetEnvironmentStrings Lib "kernel32" Alias
"GetEnvironmentStringsA" () As String
The EnvStr.vbp project (on the CD that comes with this book) uses this function to obtain the environment strings for an application as follows: